object IntegerListProcessor {  
    
  // addOne 函数：使用 map 高阶函数，将列表中的每个整数加 1  
  def addOne(numbers: List[Int]): List[Int] = {  
    numbers.map(_ + 1)  
  }  
  
  // filterEven 函数：使用 filter 高阶函数，返回所有偶数的列表  
  def filterEven(numbers: List[Int]): List[Int] = {  
    numbers.filter(_ % 2 == 0)  
  }  
  
  // mapReduce 函数：接受一个整数列表和两个函数作为参数，  
  // 分别是映射函数和归约函数，并返回最终结果  
  def mapReduce[A, B](numbers: List[A], mapFunction: A => B, reduceFunction: (B, B) => B): B = {  
    numbers.map(mapFunction).reduce(reduceFunction)  
  }  
  
  // 示例 
  def main(args: Array[String]): Unit = {  
    val numbers = List(1, 2, 3, 4, 5)  
      
    println(s"Add one to each number: ${addOne(numbers)}")  
    println(s"Filter even numbers: ${filterEven(numbers)}")  
      
    // 假设我们要计算列表中所有偶数的平方和  
    val mapFunction: Int => Int = x => x * x  
    val reduceFunction: (Int, Int) => Int = (x, y) => x + y  
    val sumOfSquaresOfEvens = mapReduce(numbers, mapFunction, reduceFunction)  
    println(s"Sum of squares of even numbers: $sumOfSquaresOfEvens")  
  }  
}